package com.gitee.wsl.scheduler.job

import com.gitee.wsl.scheduler.job.repository.JobRepository
import com.gitee.wsl.scheduler.job.repository.LockRepository
import com.gitee.wsl.scheduler.job.repository.sample.Memory


object InMem : KJobFactory<InMemKJob, InMemKJob.Configuration> {
    override fun create(configure: InMemKJob.Configuration.() -> Unit): KJob {
        return InMemKJob(InMemKJob.Configuration().apply(configure))
    }
}

fun KJob.Companion.inMemory(configure: InMemKJob.Configuration.() -> Unit) = InMem.create(configure)

class InMemKJob(config: Configuration) : BaseKJob<InMemKJob.Configuration>(config) {

    class Configuration : BaseKJob.Configuration() {
        /**
         * The timeout until a kjob instance is considered dead if no 'I am alive' notification occurred
         */
        var expireLockInMinutes = 5L
    }

    override val jobRepository: JobRepository = JobRepository.Memory


    override val lockRepository: LockRepository = LockRepository.Memory(config)
}